<?php

class BookController extends AdminController
{
	
	public function actionIndex()
	{
		$this->navText = '书籍: 书籍管理';
		
		$books = Modules::model()->findAll();
		$this->render('index', array(
				'books'=>$books
		));
	}
	
	public function actionFlushCache()
	{
		Yii::app()->cache->flush();	
		$this->redirect(array('index'));
	}
	
	public function actionCreate() {
		echo 'this create';
	}
	
	/**
	 * 预览前台
	 * @param string $bookFlag
	 * @param string $chapterFlag
	 */
	public function actionPreview($bookFlag) {
		$book = $this->getBookInfo($bookFlag);
		$this->clearPageCache($bookFlag);
		Yii::app()->cache->delete($this->getCacheId('tableOfContents', $book->moduleId));
		$url = Yii::app()->createUrl('book/default/index', array('bookFlag'=>$bookFlag));
		$this->redirect($url);
	}
	
	public function clearPageCache($bookFlag) {
		//REMOVE CACHE
		$cacheKey = COutputCache::CACHE_KEY_PREFIX.'book_default..book/default/index...' . $bookFlag.'.';
		Yii::app()->cache->delete($cacheKey);
	}
	
}